(function(angular) {
	'use strict';
	angular.module("fs.waf").factory("piInquiryService", piInquiryService).
	filter("invoiceStatus", [ '$filter', '$locale', '$translate','piInquiryService', function($filter, $locale, $translate, piInquiryService) {
		return function(optionValue, pattern) {
			return $filter('translate')(piInquiryService.handInvoiceStatusLable(optionValue, pattern));
		};
	} ]);
	piInquiryService.$inject = [ '$q', 'loggerFactory', 'commonService', 'ajaxServiceFactory' ];
	function piInquiryService($q, loggerFactory, commonService, ajaxServiceFactory) {
		var ajaxService = ajaxServiceFactory.buildAjaxService({
			getCurrencyOptions : {
				url : 'do/cda/dataList/currenciesBySiteCode',
				method : 'get'
			},
		});
		
		function getCurrencyOptions() {
			var defer = $q.defer();
			ajaxService.getCurrencyOptions().then(function(response) {
				defer.resolve(response ? response : {});
			});
			return defer.promise;
		};
		
		function handInvoiceStatusLable(optionValue, pattern) {
			var options = {};
			if(pattern == 'I'){
				options = getTxnStatus();
			}else if(pattern == 'C'){
				options = getCmStatus();
			}else{
				return ;
			}
			var optionLabel = '';
			if(options) {
				angular.forEach(options.data, function(obj, index) {
					if(optionValue == obj.value) {
						optionLabel = obj.label;
					}
				});
			}
			return optionLabel;
		}
		
		function getTxnStatus() {
			var options = {
				"data" : [{
					"label" : "label.txnstatus.c",
					"value" : "C"
				}, {
					"label" : "label.txnstatus.w",
					"value" : "W"    
				}, {
					"label" : "label.txnstatus.l",
					"value" : "L"    
				}, {
					"label" : "label.txnstatus.j",
					"value" : "J"    
				}, {
					"label" : "label.txnstatus.z",
					"value" : "Z"    
				}, {
					"label" : "label.txnstatus.f",
					"value" : "F"    
				}, {
					"label" : "label.txnstatus.r",
					"value" : "R"    
				}, {
					"label" : "label.txnstatus.x",
					"value" : "X"    
				}, {
					"label" : "label.txnstatus.p",
					"value" : "P"    
				}, {
					"label" : "label.txnstatus.m",
					"value" : "M"    
				} , {
					"label" : "label.txnstatus.o",
					"value" : "O"    
				} ]
			};
			return options;
		}
		
		function getCmStatus() {
			var options = {
					"data" : [{
						"label" : "label.txnstatus.c",
						"value" : "C"
					}, {
						"label" : "label.txnstatus.w",
						"value" : "W"    
					}, {
						"label" : "label.txnstatus.l",
						"value" : "L"    
					}, {
						"label" : "label.txnstatus.j",
						"value" : "J"    
					}, {
						"label" : "label.txnstatus.z",
						"value" : "Z"    
					}, {
						"label" : "label.creditmemo.f",
						"value" : "F"    
					}, {
						"label" : "label.txnstatus.r",
						"value" : "R"    
					}, {
						"label" : "label.txnstatus.x",
						"value" : "X"    
					}, {
						"label" : "label.txnstatus.p",
						"value" : "P"    
					}, {
						"label" : "label.txnstatus.m",
						"value" : "M"    
					} ]
				};
			return options;
		}
		
		function getYesNoStatus() {
			var options = {
					"data" : [{
						"label" : "label.global.yes",
						"value" : "Y"
					}, {
						"label" : "label.global.no",
						"value" : "N"    
					}]
				};
			return options;
		}
		
		function getInvpayStatus() {
			var options = {
					"data" : [ {
						"label" : "label.invpaystatus.c",
						"value" : "C"
					}, {
						"label" : "label.invpaystatus.d",
						"value" : "D"    
					}, {
						"label" : "label.invpaystatus.e",
						"value" : "E"    
					}, {
						"label" : "label.invpaystatus.f",
						"value" : "F"    
					},{
						"label" : "label.invpaystatus.j",
						"value" : "J"    
					}, {
						"label" : "label.invpaystatus.o",
						"value" : "O"    
					}, {
						"label" : "label.invpaystatus.r",
						"value" : "R"    
					}, {
						"label" : "label.invpaystatus.x",
						"value" : "X"    
					}, {
						"label" : "label.invpaystatus.w",
						"value" : "W"    
					}]
				};
			return options;
		}
		
		return {
				handInvoiceStatusLable :  handInvoiceStatusLable,
				getTxnStatus : getTxnStatus,
				getCmStatus : getCmStatus,
				getInvpayStatus : getInvpayStatus,
				getYesNoStatus : getYesNoStatus,
				getCurrencyOptions : getCurrencyOptions
		};
	}
})(angular);